#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: bao
# @Date:   2017-01-16 11:59:29
# @Last Modified by:   bao
# @Last Modified time: 2017-01-23 22:52:27

from Flow import *


class Job:
    """
    Each job contains at least one flow. Each flow in the job
    For example, flow 3 will start just after flow 2 finished transferring.
    """

    def __init__(self, jobId=0):
        self.jobId = jobId
        self.flowNums = 0
        self.jobStartTime = 0.0
        self.jobFinishTime = 0.0
        self.flows = []
        self.curFlowId = 0

    def SetFlows(self, flowNums, flowInfoList, startTime):
        """
        flowInfList contain <flowNums> element and each element is formed as:
        (startId, endId, flowSize)
        """
        self.flowNums = flowNums
        self.jobStartTime = startTime
        self.jobFinishTime = startTime
        # add each flow into flow list
        for i in range(flowNums):
            f = Flow()
            f.startId = flowInfoList[i][0]
            f.endId = flowInfoList[i][1]
            f.remainSize = flowInfoList[i][2]
            f.startTime = startTime
            f.finishTime = startTime
            self.flows.append(f)

    def GetNewFlow(self):
        self.curFlowId += 1
        if self.curFlowId > self.flowNums:
            return None
        return self.flows[self.curFlowId]

    def __del__(self):
        pass
